
#define CommInOut_MB_Variable
#include "userDef.h"
OutdoorMachineType OutdoorMachine;
CommInOut_MB_typeDef CommInOut_MB;
void CommInOut_MB_Txd_Data_82( void );
void CommInOut_MB_Rxd_Data_02( void );
void CommInOut_MB_Txd_Data_8A( void );
void CommInOut_MB_Rxd_Data_0A( void );
void CommInOut_MB_Rxd_Data( void );
void CommInOut_MB_Txd_Data( void );


void JudgeMachineHorsepowerSpeedSetValue( void )
{
    if ( MachineHorsepower == P_5_0 ) // 5P 机型
    {
        speedSetValue = Silence_Speed;
    }
    else if ( MachineHorsepower == P_3_0 ) // 3P 机型
    {
        speedSetValue = Silence_Speed;
    }
    else if ( MachineHorsepower == P_2_0 ) // 预留 2P 机型
    {
        speedSetValue = Silence_Speed;
    }
    else if ( MachineHorsepower == P_1_5 ) // 预留 1.5P 机型
    {
        speedSetValue = Silence_Speed;
    }
    else // 其他机型
    {
        speedSetValue = Silence_Speed;
    }
}


void Tm_500us_CommInOut_MB( void )
{
    if ( send_data_delay_time < 0xFF )
    {
        send_data_delay_time++;
    }

    if ( CommInOut_MB.timeout_rxd > 0 )
    {
        CommInOut_MB.timeout_rxd--;
    }
}


void Tm_1s_CommInOut_MB( void )
{
    if ( CommInOut_Type1 == 0 )
    {
        if ( timer_CommInOut_MB_err > 0 )
        {
            timer_CommInOut_MB_err--;
        }
        else 
        {
            f_CommInOut_MB_Err = ON;
        }
    }
    else 
    {
        f_CommInOut_MB_Err = OFF;
    }
}


void CommInOut_MB_Tx( U8 * tx_buf, U16 tx_num ) /* wifi通讯发送 */
{
    // IO_485EN_ON;
    CommInOut_MB.tx_address = tx_buf;
    CommInOut_MB.tx_count = tx_num;
    CommInOut_MB_Tx_Intp();
}


void CommInOut_MB_Tx_Intp( void ) /* wifi通讯发送中断 */
{
    if ( CommInOut_MB.tx_count > 0 )
    {
        SCI1->TXD2 = *CommInOut_MB.tx_address;
        CommInOut_MB.tx_address++;
        CommInOut_MB.tx_count--;
    }
    else 
    {
        CommInOut_MB_Rx( CommInOut_MB.Cache, LENGTH_Cache );
    }
}


void CommInOut_MB_Rx( U8 * rx_buf, U16 rx_num ) /* wifi通讯接收 */
{
    // IO_485EN_OFF;
    memset( CommInOut_MB.Cache, 0, sizeof( CommInOut_MB.Cache ) );
    CommInOut_MB.rx_count = 0U;
    CommInOut_MB.rx_length = rx_num;
    CommInOut_MB.rx_address = rx_buf;
}


void CommInOut_MB_Rx_Intp( U8 data ) /* wifi通讯接收中断 */
{
    if ( CommInOut_MB.tx_count > 0 )
    {
        return;
    }

    if ( CommInOut_MB.rx_length > CommInOut_MB.rx_count )
    {
        *CommInOut_MB.rx_address = data;
        CommInOut_MB.rx_address++;
        CommInOut_MB.rx_count++;
        CommInOut_MB.timeout_rxd = 80;
    }
}


void CommInOut_MB_Act( void )
{
    static U8 bool_init = OFF;
    U8      i = 0, checksum = 0;

    if ( bool_init == OFF )
    {
        bool_init = ON;
        CommInOut_MB_Rx( CommInOut_MB.Cache, LENGTH_Cache );
    }

    if ( CommInOut_MB.timeout_rxd == 0 && CommInOut_MB.rx_count > 0 ) /* 接收完一包数据 */
    {
        // IO_485EN_ON;
        CommInOut_MB.rx_count = 0;
        for ( i = 1; i < 17; i++ )
        {
            checksum += CommInOut_MB.Cache[i];
        }

        checksum = ~checksum;
        if ( CommInOut_MB.Cache[0] == 0xAA && CommInOut_MB.Cache[1] == 0x01 && CommInOut_MB.Cache[2] == 0x01 // 
        && CommInOut_MB.Cache[17] == 0x55 && CommInOut_MB.Cache[18] == checksum )
        {
            CommInOut_MB_Rxd_Data();
            send_data_flag_01 = 1;
            send_data_delay_time = 0;
            timer_CommInOut_MB_err = 60 * 5; /* 60s无通讯报故障 */
            f_CommInOut_MB_Err = OFF;   /* 清除通讯故障 */
        }
        else if ( CommInOut_MB.Cache[0] == 0xAA && CommInOut_MB.Cache[1] == 0x01 && CommInOut_MB.Cache[2] == 0x02 //
        && CommInOut_MB.Cache[17] == 0x55 && CommInOut_MB.Cache[18] == checksum )
        {
            CommInOut_MB_Rxd_Data_02(); // 预留
            send_data_flag_02 = 1;
            send_data_delay_time = 0;
            timer_CommInOut_MB_err = 60 * 5; /* 60s无通讯报故障 */
            f_CommInOut_MB_Err = OFF;   /* 清除通讯故障 */
        }
        else if ( CommInOut_MB.Cache[0] == 0xAA && CommInOut_MB.Cache[1] == 0x01 && CommInOut_MB.Cache[2] == 0x0A // 检测仪
        && CommInOut_MB.Cache[17] == 0x55 && CommInOut_MB.Cache[18] == checksum )
        {
            CommInOut_MB_Rxd_Data_0A(); // 检测仪
            send_data_flag_0A = 1;
            send_data_delay_time = 0;
            timer_CommInOut_MB_err = 60 * 5; /* 60s无通讯报故障 */
            f_CommInOut_MB_Err = OFF;   /* 清除通讯故障 */
        }
        else 
        {
            CommInOut_MB_Rx( CommInOut_MB.Cache, LENGTH_Cache );
        }
    }

    if ( ( send_data_flag_01 == 1 || send_data_flag_02 == 1 || send_data_flag_0A == 1 ) //
    && send_data_delay_time >= 200 )
    {
        if ( send_data_flag_01 == 1 )
        {
            CommInOut_MB_Txd_Data();
            send_data_flag_01 = 0;
        }
        else if ( send_data_flag_02 == 1 )
        {
            CommInOut_MB_Txd_Data_82();
            send_data_flag_02 = 0;
        }
        else if ( send_data_flag_0A == 1 )
        {
            CommInOut_MB_Txd_Data_8A();
            send_data_flag_0A = 0;
        }

        CommInOut_MB_Tx( CommInOut_MB.Cache, 19 );
    }

    /*
     if ( send_data_flag_PerformanceTest == 1 && send_data_delay_time >= 200 )
     {
         send_data_flag_PerformanceTest=0;
         if(PerformanceTest.PerformanceTestOccurFlag==1)
         {
          CommInOut_MB_Txd_Data_02();
          CommInOut_MB_Tx( CommInOut_MB.Cache, 19 );
         }
     }
     */
}


void CommInOut_MB_Rxd_Data_0A( void )
{
    static U8 s_quickTestCmdPre = OFF;
    U8      at_quickTestCmd = CommInOut_MB.Cache[4];

    if ( at_quickTestCmd != s_quickTestCmdPre )
    {
        if ( at_quickTestCmd == 1 )
        {
            f_quickTest = ON;
            Inside_Customer.TestType = 1;
        }
        else if ( at_quickTestCmd == 2 )
        {
            Inside_Customer.TestType = 2;
        }
        else if ( at_quickTestCmd == 3 )
        {
            Inside_Customer.TestType = 3;
        }
        else 
        {
            f_quickTest = OFF;
            Inside_Customer.TestType = 0;
        }

        //quickTest();
    }

    s_quickTestCmdPre = at_quickTestCmd;
}


void CommInOut_MB_Rxd_Data_02( void )
{
    OutdoorMachine.head = CommInOut_MB.Cache[Out_head];
    OutdoorMachine.address = CommInOut_MB.Cache[Out_address]; //地址码
    OutdoorMachine.Message = CommInOut_MB.Cache[Out_Message]; //信息码
    OutdoorMachine.DataLength = CommInOut_MB.Cache[Out_DataLength]; //数据长度
    OutdoorMachine.AD_Current = CommInOut_MB.Cache[Out_AD_Current]; //数据1 电流AD值
    OutdoorMachine.AD_Voltage = CommInOut_MB.Cache[Out_AD_Voltage]; //数据2 电压AD值
    OutdoorMachine.AD_EvaporatorExit = CommInOut_MB.Cache[Out_AD_EvaporatorExit]; //数据3 内蒸发器出口AD值
    OutdoorMachine.AD_Exhaust = CommInOut_MB.Cache[Out_AD_Exhaust]; // 数据4 排气AD值
    OutdoorMachine.AD_OutPipe = CommInOut_MB.Cache[Out_AD_OutPipe]; // 数据5 外管温度AD值
    OutdoorMachine.AD_OutEnvironment = CommInOut_MB.Cache[Out_AD_OutEnvironment]; //数据6 外环境AD值
    OutdoorMachine.AD_OutSuction = CommInOut_MB.Cache[Out_AD_OutSuction]; // 数据7 室外吸气AD值
    OutdoorMachine.AD_ModuleTemp = CommInOut_MB.Cache[Out_AD_ModuleTemp]; // 数据8 模块温度AD值
    OutdoorMachine.OutFunction = CommInOut_MB.Cache[Out_OutFunction]; // 数据9 室外机能
    OutdoorMachine.BusinessCode = CommInOut_MB.Cache[Out_BusinessCode]; // 数据10 商检机型码
    OutdoorMachine.CompCode = CommInOut_MB.Cache[Out_CompCode]; // 数据11 压缩机码
    OutdoorMachine.MachineSelectCode = CommInOut_MB.Cache[Out_MachineSelectCode]; //数据12 机型选择码
    OutdoorMachine.Reserve = CommInOut_MB.Cache[Out_Reserve]; //数据13 预留
    OutdoorMachine.FinishCode = CommInOut_MB.Cache[Out_FinishCode]; // 数据14 结束码
    OutdoorMachine.CheckSum = CommInOut_MB.Cache[Out_CheckSum]; // 数据 校验码
}


void CommInOut_MB_Rxd_Data( void )
{
    U8      local_outModeRxd;

    // parameter_out.indoorNum = ;
    // parameter_out.capacity = ;
    // parameter_out.comp_type = ;
    // parameter_out.ofan_type = ;
    // f_CompHeater = 0;
    // f_OutCSelf = 0;
    // f_ExpExist = ;
    // f_ExpRest = ;
    parameter_out.comp_freq = CommInOut_MB.Cache[5];
    if ( parameter_out.comp_freq > 0 )
    {
        f_CompOn = 1;
    }
    else 
    {
        f_CompOn = 0;
    }

    if ( CommInOut_MB.Cache[6] &0x08 )
    {
        f_4way  = 1;
    }
    else 
    {
        f_4way  = 0;
    }

    if ( CommInOut_MB.Cache[6] &0x80 )
    {
        f_HeaterOut = 1;
    }
    else 
    {
        f_HeaterOut = 0;
    }

    parameter_out.ofan_speed = CommInOut_MB.Cache[13] *10;
    local_outModeRxd = parameter_out.run_mode;
    if ( CommInOut_MB.Cache[6] &0x01 )
    {
        parameter_out.run_mode = RXFORECALL;
    }
    else if ( ( CommInOut_MB.Cache[4] &0x0F ) == 0 )
    {
        parameter_out.run_mode = RXOFF;
    }
    else if ( ( CommInOut_MB.Cache[4] &0x0F ) == 1 )
    {
        parameter_out.run_mode = RXCOOL;
    }
    else if ( ( CommInOut_MB.Cache[4] &0x0F ) == 2 )
    {
        parameter_out.run_mode = RXFAN;
    }
    else if ( ( CommInOut_MB.Cache[4] &0x0F ) == 3 )
    {
        parameter_out.run_mode = RXDRY;
    }
    else if ( ( CommInOut_MB.Cache[4] &0x0F ) == 4 )
    {
        parameter_out.run_mode = RXHEAT;
    }

    // if (parameter_out.run_mode == RXFORCEDEF)
    // {
    //     set_manual_defrost(OFF);
    // }
    if ( local_outModeRxd == RXFORECALL )
    {
        if ( parameter_out.run_mode != RXFORECALL )
        {
            if ( f_FoRecall == 1 )
            {
                f_FoRecall = 0;
                stat_FoRecall = 2;
            }
        }
    }
    else 
    {
        if ( parameter_out.run_mode == RXFORECALL )
        {
            if ( f_FoRecall == 0 )
            {
                f_FoRecall = 1;
                stat_FoRecall = 1;
            }
        }
    }

    if ( local_outModeRxd == RXTESTRUN )
    {
        if ( parameter_out.run_mode != RXTESTRUN )
        {
            TestRunStat = 0;
        }
    }
    else 
    {
        if ( parameter_out.run_mode == RXTESTRUN )
        {
            TestRunStat = 2;
        }
    }

    if ( b_power.run == ON && e_mode.run == MODEHEAT )
    {
        if ( ( parameter_out.run_mode != RXHEAT ) && ( parameter_out.run_mode != RXFORCEHEAT ) && ( parameter_out.run_mode != RXFORCEDEF ) && ( parameter_out.run_mode != RXHEATTEST ) )
        {
            f_ModeClash = 1;
        }
        else 
        {
            f_ModeClash = 0;
        }
    }

    parameter_out.eve_value = ( ( U16 ) CommInOut_MB.Cache[11] << 8 ) +CommInOut_MB.Cache[12];

    // parameter_out.ac_voltage = ; /* 接收到的外机交流电压 */
    // parameter_out.dc_voltage = ; /* 接收到的直流母线电压 */
    // parameter_out.ac_current = ; /* 接收到的外机交流电流 * 10 */
    // parameter_out.dc_current = ; /* 接收到的压缩机相电流 * 10 */
    // temp.outdoor = ; /* (实际室外环温值 + 40) * 10 */
    // temp.out_tube = ; /* (实际室外铜管温值 + 40) * 10 */
    // temp.out_exha = ; /* (实际室外排气温值 + 40) * 10 */
    // temp.comp_ipm = ; /* (实际室外压缩机温值 + 40) * 10 */
    // f_KeepHumToFan = ;
    if ( CommInOut_MB.Cache[6] &0x04 )
    {
        f_Defrosting = 1;
        set_manual_defrost( OFF );
    }
    else 
    {
        f_Defrosting = 0;
    }

    // if (f_commData15_b3)
    // {
    //     TempA = parameter_out.run_mode;
    //     if (TempA == RXHEAT || TempA == RXFORCEHEAT || TempA == RXHEATTEST || TempA == RXFORCEDEF)
    //     {
    //         f_Defrosting = 1;
    //         f_CoolOilBack = 0;
    //         f_HeatOilBack = 1;
    //     }
    //     else
    //     {
    //         f_CoolOilBack = 1;
    //         f_HeatOilBack = 0;
    //     }
    // }
    // else
    // {
    //     f_CoolOilBack = 0;
    //     f_HeatOilBack = 0;
    // }
    // f_wait = ;
    // f_outquiet = ;
    // f_outCondensation = ;
    // if (parameter_out.indoorNum > 1)
    // {
    // if (f_commData0_b5 == 1)
    // {
    //     f_RoomUnitOn = 0;
    // }
    // else
    // {
    if ( b_power.run == ON && f_CompOn == 1 ) // && parameter_out.eve_value >= 70)
    {
        f_RoomUnitOn = 1;
    }
    else 
    {
        f_RoomUnitOn = 0;
    }

    // }
    // }
    // else
    // {
    //     if (f_CompOn == 0)
    //     {
    //         f_RoomUnitOn = 0;
    //     }
    //     else
    //     {
    //         if (b_power.run && f_CompOn)
    //         {
    //             f_RoomUnitOn = 1;
    //         }
    //         else
    //         {
    //             f_RoomUnitOn = 0;
    //         }
    //     }
    // }

    /*	
        OutSafeErr0 = 0;
        OutSafeErr1 = 0;
        OutSafeErr2 = 0;
        OutSafeErr3 = 0;
        OutSafeErr4 = 0;
        OutSafeErr5 = 0;
        OutSafeErr6 = 0;
        OutSafeErr7 = 0;
        OutSafeErr8 = 0;
        */
    if ( CommInOut_MB.Cache[7] &0x80 ) //  cxs  bit7是室外IPM故障      E9
    {
        OutSafeErr4 |= 0x80;
    }
    else 
    {
        OutSafeErr4 &= 0x7F;
    }

    if ( CommInOut_MB.Cache[7] &0x40 ) //  cxs  bit6是排气温度故障        E8
    {
        OutSafeErr4 |= 0x40;
    }
    else 
    {
        OutSafeErr4 &= 0xBF;
    }

    if ( CommInOut_MB.Cache[7] &0x20 ) //  cxs  bit5是室外环境传感器故障       E7
    {
        OutSafeErr4 |= 0x20;
    }
    else 
    {
        OutSafeErr4 &= 0xDF;
    }

    if ( CommInOut_MB.Cache[7] &0x10 ) //  cxs  是系统故障（缺氟）E6
    {
        OutSafeErr4 |= 0x10;
    }
    else 
    {
        OutSafeErr4 &= 0xEF;
    }

    if ( CommInOut_MB.Cache[7] &0x08 ) //  cxs 系统故障（缺氟）E4
    {
        OutSafeErr4 |= 0x08;
    }
    else 
    {
        OutSafeErr4 &= 0xF7;
    }

    if ( CommInOut_MB.Cache[7] &0x04 ) //  cxs  bit2是室外盘管温度传感器故障             E1
    {
        OutSafeErr4 |= 0x04;
    }
    else 
    {
        OutSafeErr4 &= 0xFB;
    }

    if ( CommInOut_MB.Cache[7] &0x02 ) // cxs  bit1是室外通讯故障        EC
    {
        OutSafeErr4 |= 0x02;
    }
    else 
    {
        OutSafeErr4 &= 0xFD;
    }

    if ( CommInOut_MB.Cache[7] &0x01 ) // cxs  bit0是 室内外通信故障         E0
    {
        OutSafeErr4 |= 0x01;
    }
    else 
    {
        OutSafeErr4 &= 0xFE;
    }

    if ( CommInOut_MB.Cache[8] &0x80 ) // cxs 电流保护 P2
    {
        OutSafeErr6 |= 0x80;
    }
    else 
    {
        OutSafeErr6 &= 0x7F;
    }

    if ( CommInOut_MB.Cache[8] &0x40 ) //  cxs 电压过高（过低）保护 P1
    {
        OutSafeErr6 |= 0x40;
    }
    else 
    {
        OutSafeErr6 &= 0xBF;
    }

    if ( CommInOut_MB.Cache[8] &0x20 ) //  cxs 吸气传感器故障
    {
        OutSafeErr6 |= 0x20;
    }
    else 
    {
        OutSafeErr6 &= 0xDF;
    }

    if ( CommInOut_MB.Cache[8] &0x10 ) //  cxs 室外电压传感器故障 EU
    {
        OutSafeErr6 |= 0x10;
    }
    else 
    {
        OutSafeErr6 &= 0xEF;
    }

    if ( CommInOut_MB.Cache[8] &0x08 ) // cxs 壳顶故障
    {
        OutSafeErr6 |= 0x08;
    }
    else 
    {
        OutSafeErr6 &= 0xF7;
    }

    if ( CommInOut_MB.Cache[8] &0x04 ) // cxs EEPROM故障  EE
    {
        OutSafeErr6 |= 0x04;
    }
    else 
    {
        OutSafeErr6 &= 0xFB;
    }

    if ( CommInOut_MB.Cache[8] &0x02 ) //  cxs 室外电流传感器故障 EA
    {
        OutSafeErr6 |= 0x02;
    }
    else 
    {
        OutSafeErr6 &= 0xFD;
    }

    if ( CommInOut_MB.Cache[8] &0x01 ) // cxs 直流风机故障
    {
        OutSafeErr6 |= 0x01;
    }
    else 
    {
        OutSafeErr6 &= 0xFE;
    }

    if ( CommInOut_MB.Cache[9] &0x80 ) // cxs 直流风机保护
    {
        OutSafeErr7 |= 0x80;
    }
    else 
    {
        OutSafeErr7 &= 0x7F;
    }

    if ( CommInOut_MB.Cache[9] &0x40 ) //cxs IPM保护
    {
        OutSafeErr7 |= 0x40;
    }
    else 
    {
        OutSafeErr7 &= 0xBF;
    }

    if ( CommInOut_MB.Cache[9] &0x20 ) // cxs 压缩机驱动保护 P9
    {
        OutSafeErr7 |= 0x20;
    }
    else 
    {
        OutSafeErr7 &= 0xDF;
    }

    if ( CommInOut_MB.Cache[9] &0x10 ) // cxs 室外环境温度过高过低保护 P8
    {
        OutSafeErr7 |= 0x10;
    }
    else 
    {
        OutSafeErr7 &= 0xEF;
    }

    if ( CommInOut_MB.Cache[9] &0x08 ) // cxs 室内盘管制热过热保护 P7
    {
        OutSafeErr7 |= 0x08;
    }
    else 
    {
        OutSafeErr7 &= 0xF7;
    }

    if ( CommInOut_MB.Cache[9] &0x04 ) // cxs 室外盘管温度过高保护 P6
    {
        OutSafeErr7 |= 0x04;
    }
    else 
    {
        OutSafeErr7 &= 0xFB;
    }

    if ( CommInOut_MB.Cache[9] &0x02 ) // cxs 室内盘管制冷过冷保护 P5
    {
        OutSafeErr7 |= 0x02;
    }
    else 
    {
        OutSafeErr7 &= 0xFD;
    }

    if ( CommInOut_MB.Cache[9] &0x01 ) // cxs 室外排气温度过高保护  P4
    {
        OutSafeErr7 |= 0x01;
    }
    else 
    {
        OutSafeErr7 &= 0xFE;
    }

    if ( CommInOut_MB.Cache[10] &0x80 ) //cxs 预留
    {
        OutSafeErr8 |= 0x80;
    }
    else 
    {
        OutSafeErr8 &= 0x7F;
    }

    if ( CommInOut_MB.Cache[10] &0x40 ) //cxs 预留
    {
        OutSafeErr8 |= 0x40;
    }
    else 
    {
        OutSafeErr8 &= 0xBF;
    }

    if ( CommInOut_MB.Cache[10] &0x20 ) // cxs 预留
    {
        OutSafeErr8 |= 0x20;
    }
    else 
    {
        OutSafeErr8 &= 0xDF;
    }

    if ( CommInOut_MB.Cache[10] &0x10 ) // cxs 压缩机驱动故障
    {
        OutSafeErr8 |= 0x10;
    }
    else 
    {
        OutSafeErr8 &= 0xEF;
    }

    if ( CommInOut_MB.Cache[10] &0x08 ) // cxs 内蒸发器出口4传感器故障（IPT出口传感器放在室外时有效）
    {
        OutSafeErr8 |= 0x08;
    }
    else 
    {
        OutSafeErr8 &= 0xF7;
    }

    if ( CommInOut_MB.Cache[10] &0x04 ) // cxs 内蒸发器出口3传感器故障（IPT出口传感器放在室外时有效）
    {
        OutSafeErr8 |= 0x04;
    }
    else 
    {
        OutSafeErr8 &= 0xFB;
    }

    if ( CommInOut_MB.Cache[10] &0x02 ) // cxs 内蒸发器出口2传感器故障（IPT出口传感器放在室外时有效）
    {
        OutSafeErr8 |= 0x02;
    }
    else 
    {
        OutSafeErr8 &= 0xFD;
    }

    if ( CommInOut_MB.Cache[10] &0x01 ) // cxs 内蒸发器出口1传感器故障（IPT出口传感器放在室外时有效）
    {
        OutSafeErr8 |= 0x01;
    }
    else 
    {
        OutSafeErr8 &= 0xFE;
    }

    if ( CommInOut_MB.Cache[15] &0x04 ) // 外机是否有进行有开始自清洁
    {
        CleanSelfData.OutCleanStartFlag = 1;
    }
    else 
    {
        CleanSelfData.OutCleanStartFlag = 0;
    }

    /*
        OutSafeErr0 = commData0;
        OutSafeErr1 = commData1;
        OutSafeErr2 = commData2;
        OutSafeErr3 = commData3;
        OutSafeErr4 = commData4;
        OutSafeErr5 = commData5;
        OutSafeErr6 = commData6;
        OutSafeErr7 = commData7;
        OutSafeErr8 = commData8;
    */
    // speedSetValueRxd = commData13;
    // temp.gas_pipe = commData14 * 10;
    // temp.liquid_pipe = commData15 * 10;
}


void CommInOut_MB_Txd_Data_8A( void )
{
    U8      i = 0, checksum = 0;

    memset( CommInOut_MB.Cache, 0, sizeof( CommInOut_MB.Cache ) );

    //
    CommInOut_MB.Cache[0] = 0xAA;       //	头码	0xAA	固定	
    CommInOut_MB.Cache[1] = 0x01;       //	地址码	0x01	固定	
    CommInOut_MB.Cache[2] = 0x8A;       //	信息码	0x8A	固定	
    CommInOut_MB.Cache[3] = 13;         //	数据长度	0x0D	固定	
    CommInOut_MB.Cache[4] = PROGRAM_VER; //	数据1 	内机板软件版本	
    CommInOut_MB.Cache[5] = PROGRAM_CODING_0; //	数据2 	内机板软件编码D0 
    CommInOut_MB.Cache[6] = PROGRAM_CODING_1; //	数据3 	内机板软件编码D1 
    CommInOut_MB.Cache[7] = PROGRAM_CODING_2; //	数据4 	内机板软件编码D2 
    CommInOut_MB.Cache[8] = PROGRAM_CODING_3; //	数据5 	内机板软件编码D3 
    if ( Fanmotor_Type == OFF ) // 直流风机
    {
        CommInOut_MB.Cache[9] = BOARD_CODING_DC_FAN_0; //	数据6 	内机板编码D0	
        CommInOut_MB.Cache[10] = BOARD_CODING_DC_FAN_1; //	数据7 	内机板编码D1	
        CommInOut_MB.Cache[11] = BOARD_CODING_DC_FAN_2; //	数据8 	内机板编码D2	
        CommInOut_MB.Cache[12] = BOARD_CODING_DC_FAN_3; //	数据9 	内机板编码D3	
        CommInOut_MB.Cache[13] = BOARD_CODING_DC_FAN_4; //	数据10	内机板编码D4	
    }
    else // 交流风机
    {
        CommInOut_MB.Cache[9] = BOARD_CODING_AC_FAN_0; //	数据6 	内机板编码D0	
        CommInOut_MB.Cache[10] = BOARD_CODING_AC_FAN_1; //	数据7 	内机板编码D1	
        CommInOut_MB.Cache[11] = BOARD_CODING_AC_FAN_2; //	数据8 	内机板编码D2	
        CommInOut_MB.Cache[12] = BOARD_CODING_AC_FAN_3; //	数据9 	内机板编码D3	
        CommInOut_MB.Cache[13] = BOARD_CODING_AC_FAN_4; //	数据10	内机板编码D4	
    }

    CommInOut_MB.Cache[14] = Inside_Customer.TestType; //	数据11	返回编码值	
    CommInOut_MB.Cache[15] = Inside_Customer.Encode; //	数据12	0x00 拨码卡关的编码值		
    CommInOut_MB.Cache[16] = Inside_Customer.InternalEngineFlag; //	数据13	0x00 内机状态发送给 手控仪 ，bit0： 0水未满，1水满；bit1 0水泵未开，1水泵开启
    CommInOut_MB.Cache[17] = 0x55;      //	结束码	0x55	固定	
    for ( i = 1; i < 17; i++ )
    {
        checksum += CommInOut_MB.Cache[i];
    }

    checksum = ~checksum;
    CommInOut_MB.Cache[18] = checksum;  //	校验码		计算校验码 
}


void CommInOut_MB_Txd_Data_82( void )
{
    U8      i = 0, checksum = 0;

    memset( CommInOut_MB.Cache, 0, sizeof( CommInOut_MB.Cache ) );
    CommInOut_MB.Cache[0] = 0xAA;
    CommInOut_MB.Cache[1] = 0x01;
    CommInOut_MB.Cache[2] = 0x82;
    CommInOut_MB.Cache[3] = 13;
    if ( b_power.run == OFF )
    {
        CommInOut_MB.Cache[4] = 0x10;
    }
    else if ( e_mode.run == MODECOOL )
    {
        CommInOut_MB.Cache[4] |= 0x11;
    }
    else if ( e_mode.run == MODEFAN )
    {
        CommInOut_MB.Cache[4] |= 0x12;
    }
    else if ( e_mode.run == MODEDRY )
    {
        CommInOut_MB.Cache[4] |= 0x13;
    }
    else if ( e_mode.run == MODEHEAT )
    {
        CommInOut_MB.Cache[4] |= 0x14;
    }

    if ( Inside_Customer.TestType == 1 ) // 厂内性能测试 
    {
        if ( e_mode.run == MODECOOL )
        {
            CommInOut_MB.Cache[4] |= 0x11;
        }

        if ( e_mode.run == MODEHEAT )
        {
            CommInOut_MB.Cache[4] |= 0x14;
        }
    }

    if ( Inside_Customer.TestType == 2 ) // 客户商检制冷 写固定值 0x11
    {
        CommInOut_MB.Cache[4] = 0x11;
    }

    if ( Inside_Customer.TestType == 3 ) // 客户商检 制热 写固定值 0x14
    {
        CommInOut_MB.Cache[4] = 0x14;
    }

    if ( PerformanceTest.PerformanceTestOccurFlag == 1 ) // 标定，性能测试的时候,发送检测频率偏移量
    {
        CommInOut_MB.Cache[5] = 127 + PerformanceTest.CompFrequencyOffset;
    }

    if ( b_manual_defrost.set == 1 )
    {
        CommInOut_MB.Cache[6] |= 0x80;
    }

    if ( f_FoRecall == 1 ) // 收氟
    {
        CommInOut_MB.Cache[6] |= 0x80;
    }
    else 
    {
        CommInOut_MB.Cache[6] &= 0x7F;
    }

    if ( b_eco.run )
    {
        CommInOut_MB.Cache[6] |= 0x20;
    }

    if ( f_eepRom )
    {
        CommInOut_MB.Cache[6] |= 0x10;
    }

    if ( l_timerOn.run || l_timerOff.run )
    {
        CommInOut_MB.Cache[6] |= 0x08;
    }

    if ( e_fanStep.run == FANLEVEL7 )
    {
        CommInOut_MB.Cache[6] |= 0x02;
    }

    if ( ( b_sleep.set ) && ( PerformanceTest.PerformanceTestOccurFlag == 0 ) )
    {
        //speedSetValue = 700;
        JudgeMachineHorsepowerSpeedSetValue();
        CommInOut_MB.Cache[6] |= 0x01;
    }

  

    if ( f_TubeErr || f_TubeErrQT )
    {
        CommInOut_MB.Cache[7] |= 0x80;
    }

    if ( f_RoomErr || f_RoomErrQT )
    {
        CommInOut_MB.Cache[7] |= 0x40;
    }

    if ( f_MotorErr )
    {
        CommInOut_MB.Cache[7] |= 0x20;
    }

    if ( f_eepErr )
    {
        CommInOut_MB.Cache[7] |= 0x10;
    }

    if ( f_comm485Err || f_CommErr )
    {
        CommInOut_MB.Cache[7] |= 0x08;
    }

    if ( f_waterErr )
    {
        CommInOut_MB.Cache[8] |= 0x10;
    }

    if ( ( l_tarTemp_C.run / 10 ) >= 31 ) // if (((l_tarTemp_C.run / 10) - 16) > 31)
    {
        CommInOut_MB.Cache[9] |= 0x0F;
    }
    else 
    {
        CommInOut_MB.Cache[9] |= ( ( l_tarTemp_C.run / 10 ) - 16 );
    }

    if ( ( b_sleep.set ) && ( PerformanceTest.PerformanceTestOccurFlag == 0 ) ) // 非性能测试下，设定睡眠模式
    {
        //speedSetValue = 700;
        JudgeMachineHorsepowerSpeedSetValue();
        CommInOut_MB.Cache[9] |= 0x40;
    }
    else if ( e_fanStep.run <= FANLEVEL1 ) // 小于 1
    {
        CommInOut_MB.Cache[9] |= 0x00;
    }
    else if ( e_fanStep.run <= FANLEVEL3 ) // 大于1 小于 30
    {
        CommInOut_MB.Cache[9] |= 0x10;
    }
    else if ( e_fanStep.run <= FANLEVEL5 ) // 大于 30 小于 70
    {
        CommInOut_MB.Cache[9] |= 0x20;
    }
    else if ( e_fanStep.run <= FANLEVEL6 ) // 大于 70 小于90
    {
        CommInOut_MB.Cache[9] |= 0x30;
    }
    else // 大于 90
    {
        CommInOut_MB.Cache[9] |= 0x30;
    }

    CommInOut_MB.Cache[10] = speedNowValue1 / 10; //实际转速
    if ( f_CleanSelf == ON ) // 自清洁模式
    {
        if ( temp.tube <= ( 400 - 100 ) ) // 如果管温 小于 负10 ℃
        {
            temp.tube = 400 + 100;      // 将管温钳位 于 10℃
        }
    }

    //CommInOut_MB.Cache[10] = speedSetValue / 10; //设定转速
    CommInOut_MB.Cache[11] = ( temp.tube - 200 ) >> 2;
    CommInOut_MB.Cache[12] = ( temp.room - 200 ) >> 2;
    CommInOut_MB.Cache[14] = ( ( ( temp.room - 200 ) & 0x0003 ) << 2 ) + ( ( temp.tube - 200 ) & 0x0003 );
    CommInOut_MB.Cache[15] = 0;
    if ( PerformanceTest.PerformanceTestOccurFlag == 1 ) // 性能测试
    {
        CommInOut_MB.Cache[15] |= 0x40;
    }
    else // 
    {
        CommInOut_MB.Cache[15] &= 0xBF;
    }

    if ( f_CleanSelf == ON ) // 自清洁模式
    {
        CommInOut_MB.Cache[15] |= 0x10;
    }
    else 
    {
        CommInOut_MB.Cache[15] &= 0xEF;
    }

    CommInOut_MB.Cache[16] = 0x01;
    CommInOut_MB.Cache[17] = 0x55;
    for ( i = 1; i < 17; i++ )
    {
        checksum += CommInOut_MB.Cache[i];
    }

    checksum = ~checksum;
    CommInOut_MB.Cache[18] = checksum;
}


void CommInOut_MB_Txd_Data( void )
{
    U8      i = 0, checksum = 0;

    memset( CommInOut_MB.Cache, 0, sizeof( CommInOut_MB.Cache ) );
    CommInOut_MB.Cache[0] = 0xAA;
    CommInOut_MB.Cache[1] = 0x01;
    CommInOut_MB.Cache[2] = 0x81;
    CommInOut_MB.Cache[3] = 13;
    if ( b_power.run == OFF )
    {
        CommInOut_MB.Cache[4] = 0x10;
    }
    else if ( e_mode.run == MODECOOL )
    {
        CommInOut_MB.Cache[4] |= 0x11;
    }
    else if ( e_mode.run == MODEFAN )
    {
        CommInOut_MB.Cache[4] |= 0x12;
    }
    else if ( e_mode.run == MODEDRY )
    {
        CommInOut_MB.Cache[4] |= 0x13;
    }
    else if ( e_mode.run == MODEHEAT )
    {
        CommInOut_MB.Cache[4] |= 0x14;
    }

    if ( Inside_Customer.TestType == 1 ) // 厂内性能测试 
    {
        if ( b_power.run == OFF )
        {
            CommInOut_MB.Cache[4] |= 0x10;
        }
        else if ( e_mode.run == MODECOOL )
        {
            CommInOut_MB.Cache[4] |= 0x11;
        }
        else if ( e_mode.run == MODEHEAT )
        {
            CommInOut_MB.Cache[4] |= 0x14;
        }
    }

    if ( Inside_Customer.TestType == 2 ) // 客户商检制冷 写固定值 0x11
    {
        CommInOut_MB.Cache[4] = 0x11;
    }

    if ( Inside_Customer.TestType == 3 ) // 客户商检 制热 写固定值 0x14
    {
        CommInOut_MB.Cache[4] = 0x14;
    }

    if ( PerformanceTest.PerformanceTestOccurFlag == 1 ) // 标定，性能测试的时候,发送检测频率偏移量
    {
        CommInOut_MB.Cache[5] = 127 + PerformanceTest.CompFrequencyOffset;
    }

    if ( b_manual_defrost.set == 1 )
    {
        CommInOut_MB.Cache[6] |= 0x80;
    }

    if ( f_FoRecall == 1 ) // 收氟
    {
        CommInOut_MB.Cache[6] |= 0x80;
    }
    else 
    {
        CommInOut_MB.Cache[6] &= 0x7F;
    }

    if ( b_eco.run )
    {
        CommInOut_MB.Cache[6] |= 0x20;
    }

    if ( f_eepRom )
    {
        CommInOut_MB.Cache[6] |= 0x10;
    }

    if ( l_timerOn.run || l_timerOff.run )
    {
        CommInOut_MB.Cache[6] |= 0x08;
    }

    if ( e_fanStep.run == FANLEVEL7 )
    {
        CommInOut_MB.Cache[6] |= 0x02;
    }

    if ( ( b_sleep.set ) && ( PerformanceTest.PerformanceTestOccurFlag == 0 ) ) // 非性能测试下，设定睡眠模式
    {
        //speedSetValue = 700;
        JudgeMachineHorsepowerSpeedSetValue();
        CommInOut_MB.Cache[6] |= 0x01;
    }

    
    /*
     if ( b_sleep.run )
     {
         CommInOut_MB.Cache[6] |= 0x01;

     }
    */
    if ( f_TubeErr || f_TubeErrQT )
    {
        CommInOut_MB.Cache[7] |= 0x80;
    }

    if ( f_RoomErr || f_RoomErrQT )
    {
        CommInOut_MB.Cache[7] |= 0x40;
    }

    if ( f_MotorErr )
    {
        CommInOut_MB.Cache[7] |= 0x20;
    }

    if ( f_eepErr )
    {
        CommInOut_MB.Cache[7] |= 0x10;
    }

    if ( f_comm485Err || f_CommErr )
    {
        CommInOut_MB.Cache[7] |= 0x08;
    }

    if ( f_waterErr )
    {
        CommInOut_MB.Cache[8] |= 0x10;
    }

    if ( ( l_tarTemp_C.run / 10 ) >= 31 ) // if (((l_tarTemp_C.run / 10) - 16) > 31)
    {
        CommInOut_MB.Cache[9] |= 0x0F;
    }
    else 
    {
        CommInOut_MB.Cache[9] |= ( ( l_tarTemp_C.run / 10 ) - 16 );
    }

    if ( ( b_sleep.set ) && ( PerformanceTest.PerformanceTestOccurFlag == 0 ) ) // 非性能测试下，设定睡眠模式
    {
        //speedSetValue = 700;
        JudgeMachineHorsepowerSpeedSetValue();
        CommInOut_MB.Cache[9] |= 0x40;
    }
    else if ( e_fanStep.run <= FANLEVEL1 ) // 小于 1
    {
        CommInOut_MB.Cache[9] |= 0x00;
    }
    else if ( e_fanStep.run <= FANLEVEL3 ) // 大于1 小于 30
    {
        CommInOut_MB.Cache[9] |= 0x10;
    }
    else if ( e_fanStep.run <= FANLEVEL5 ) // 大于 30 小于 70
    {
        CommInOut_MB.Cache[9] |= 0x20;
    }
    else if ( e_fanStep.run <= FANLEVEL6 ) // 大于 70 小于90
    {
        CommInOut_MB.Cache[9] |= 0x30;
    }
    else // 大于 90
    {
        CommInOut_MB.Cache[9] |= 0x30;
    }

    CommInOut_MB.Cache[10] = speedNowValue1 / 10; //实际转速

    //CommInOut_MB.Cache[10] = speedSetValue / 10; //设定转速
    if ( f_CleanSelf == ON ) // 自清洁模式
    {
        if ( temp.tube <= ( 400 - 100 ) ) // 如果管温 小于 负10 ℃
        {
            temp.tube = 400 + 100;      // 将管温钳位 于 10℃
        }
    }

    CommInOut_MB.Cache[11] = ( temp.tube - 200 ) >> 2;
    CommInOut_MB.Cache[12] = ( temp.room - 200 ) >> 2;
    CommInOut_MB.Cache[14] = ( ( ( temp.room - 200 ) & 0x0003 ) << 2 ) + ( ( temp.tube - 200 ) & 0x0003 );
    CommInOut_MB.Cache[15] = 0;
    if ( PerformanceTest.PerformanceTestOccurFlag == 1 ) // 标定，性能测试
    {
        CommInOut_MB.Cache[15] |= 0x40;
    }
    else // 非 标定
    {
        CommInOut_MB.Cache[15] &= 0xBF;
    }

    if ( f_CleanSelf == ON ) // 自清洁模式
    {
        CommInOut_MB.Cache[15] |= 0x10;
    }
    else 
    {
        CommInOut_MB.Cache[15] &= 0xEF;
    }

    CommInOut_MB.Cache[16] = 0x01;
    CommInOut_MB.Cache[17] = 0x55;
    for ( i = 1; i < 17; i++ )
    {
        checksum += CommInOut_MB.Cache[i];
    }

    checksum = ~checksum;
    CommInOut_MB.Cache[18] = checksum;
}


/*
void CommInOut_MB_Txd_Data_82( void )
{
    U8      i = 0, checksum = 0;

    memset( CommInOut_MB.Cache, 0, sizeof( CommInOut_MB.Cache ) );
    CommInOut_MB.Cache[0] = 0xAA;
    CommInOut_MB.Cache[1] = 0x01;
    CommInOut_MB.Cache[2] = 0x82;
    CommInOut_MB.Cache[3] = 13;

    if ( b_power.run == OFF )
    {
        CommInOut_MB.Cache[4] = 0x10;
    }
    else if ( e_mode.run == MODECOOL )
    {
        CommInOut_MB.Cache[4] |= 0x11;
    }
    else if ( e_mode.run == MODEFAN )
    {
        CommInOut_MB.Cache[4] |= 0x12;
    }
    else if ( e_mode.run == MODEDRY )
    {
        CommInOut_MB.Cache[4] |= 0x13;
    }
    else if ( e_mode.run == MODEHEAT )
    {
        CommInOut_MB.Cache[4] |= 0x14;
    }

    CommInOut_MB.Cache[5] = ( U8 )
    PerformanceTest.CompFrequencyOffset;

    if ( b_manual_defrost.set == 1 )
    {
        CommInOut_MB.Cache[6] |= 0x80;
    }

    if ( b_eco.run )
    {
        CommInOut_MB.Cache[6] |= 0x20;
    }

    if ( f_eepRom )
    {
        CommInOut_MB.Cache[6] |= 0x10;
    }

    if ( l_timerOn.run || l_timerOff.run )
    {
        CommInOut_MB.Cache[6] |= 0x08;
    }

    if ( e_fanStep.run == FANLEVEL7 )
    {
        CommInOut_MB.Cache[6] |= 0x02;
    }

    if ( b_sleep.run )
    {
        CommInOut_MB.Cache[6] |= 0x01;
    }

    if ( f_TubeErr || f_TubeErrQT )
    {
        CommInOut_MB.Cache[7] |= 0x80;
    }

    if ( f_RoomErr || f_RoomErrQT )
    {
        CommInOut_MB.Cache[7] |= 0x40;
    }

    if ( f_MotorErr )
    {
        CommInOut_MB.Cache[7] |= 0x20;
    }

    if ( f_eepErr )
    {
        CommInOut_MB.Cache[7] |= 0x10;
    }

    if ( f_comm485Err || f_CommErr )
    {
        CommInOut_MB.Cache[7] |= 0x08;
    }

    if ( ( l_tarTemp_C.run / 10 ) >= 31 )
    {
        CommInOut_MB.Cache[9] |= 0x0F;
    }
    else 
    {
        CommInOut_MB.Cache[9] |= ( ( l_tarTemp_C.run / 10 ) - 16 );
    }

    if ( e_fanStep.run <= FANLEVEL1 )
    {
        CommInOut_MB.Cache[9] |= 0x00;
    }
    else if ( e_fanStep.run <= FANLEVEL3 )
    {
        CommInOut_MB.Cache[9] |= 0x40;
    }
    else if ( e_fanStep.run <= FANLEVEL4 )
    {
        CommInOut_MB.Cache[9] |= 0x10;
    }
    else if ( e_fanStep.run <= FANLEVEL5 )
    {
        CommInOut_MB.Cache[9] |= 0x20;
    }
    else 
    {
        CommInOut_MB.Cache[9] |= 0x30;
    }

    CommInOut_MB.Cache[10] = speedSetValue / 10;
    CommInOut_MB.Cache[11] = ( temp.tube - 200 ) >> 2;
    CommInOut_MB.Cache[12] = ( temp.room - 200 ) >> 2;
    CommInOut_MB.Cache[14] = ( ( ( temp.room - 200 ) & 0x0003 ) << 2 ) + ( ( temp.tube - 200 ) & 0x0003 );
    CommInOut_MB.Cache[15] = 0;

    if ( PerformanceTest.PerformanceTestOccurFlag == 1 ) // 标定，性能测试
    {
        CommInOut_MB.Cache[15] |= 0x40;
    }
    else // 非 标定
    {
        CommInOut_MB.Cache[15] &= 0xBF;
    }

    CommInOut_MB.Cache[16] = 0x01;
    CommInOut_MB.Cache[17] = 0x55;

    for ( i = 1; i < 17; i++ )
    {
        checksum += CommInOut_MB.Cache[i];
    }

    checksum = ~checksum;
    CommInOut_MB.Cache[18] = checksum;
}
*/
